#!/bin/bash

# ExcelSpreadPub.c  testmain.c

set -x

#export  CFLAGS=" -mno-cygwin -mrtd -DARCH_PC_WIN95 -D_MSC_VER -DWIN32 -D_DEBUG -D_LIB -D_WIN32_WINNT=0x0400 "

export  CFLAGS=" -mno-cygwin -mrtd -DARCH_PC_WIN95 -I/usr/local/include"
#export LDFLAGS=" -mno-cygwin -Wl,--compat-implib -Wl,--add-stdcall-alias -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all " 
#export LDFLAGS=" -mno-cygwin -Wl,--compat-implib -Wl,--add-stdcall-alias -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import -Wl,--enable-auto-image-base  " 
export LDFLAGS=" -mno-cygwin -mrtd -Wl,--compat-implib -Wl,--add-stdcall-alias -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import -Wl,--enable-auto-image-base  " 
cmt="/cygdrive/c/Program Files/Microsoft Visual Studio 8/VC/lib/libcmt.lib"
msvcrt="/cygdrive/c/Program Files/Microsoft Visual Studio 8/VC/lib/msvcrt.lib"

rm -f ExcelSpreadPub.o ExcelSpreadPub.a ExcelSpreadPub.dll testmain.exe testmain.o

gcc $CFLAGS -c -DBUILDING_DLL=1 -g -O2 -Wall -o ExcelSpreadPub.o ExcelSpreadPub.c

echo ==============================

#gcc $LDFLAGS -o ExcelSpreadPub.dll -shared -Wl,--output-def,ExcelSpreadPub.def -Wl,--out-implib,ExcelSpreadPub.a ExcelSpreadPub.o 
#gcc $LDFLAGS -o ExcelSpreadPub.dll -shared -Wl,--output-def,ExcelSpreadPub.def -Wl,--out-implib,ExcelSpreadPub.a ExcelSpreadPub.o -Wl,--exclude-libs,libspread.lib  libspread.lib -Wl,--exclude-libs,libspread-core.lib libspread-core.lib -Wl,--exclude-libs,"$cmt" "$cmt" -lwsock32

#gcc $CFLAGS $LDFLAGS -o ExcelSpreadPub.dll -shared -Wl,--output-def,ExcelSpreadPub.def -Wl,--out-implib,ExcelSpreadPub.a ExcelSpreadPub.c sp.c -Wl,--exclude-libs,libspread.lib  libspread.lib -Wl,--exclude-libs,libspread-core.lib libspread-core.lib -Wl,--exclude-libs,"$cmt" "$cmt" -lwsock32

gcc -shared $CFLAGS $LDFLAGS -o ExcelSpreadPub.dll -Wl,--output-def,ExcelSpreadPub.def -Wl,--out-implib,ExcelSpreadPub.a ExcelSpreadPub.o -Wl,--exclude-libs,libspread-core.a libspread-core.a -lwsock32

echo ==============================
gcc $CFLAGS  -c -g -O2 -Wall -o testmain.o testmain.c
gcc $LDFLAGS -o testmain.exe testmain.o ExcelSpreadPub.a -lwsock32 -lmsvcrt -luser32

echo ==============================

#cp ExcelSpreadPub.dll libspread.dll /cygdrive/c/dlls
cp ExcelSpreadPub.dll /cygdrive/c/cygwin/localbin
cp ExcelSpreadPub.dll /cygdrive/c/cpi

./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe
#./testmain.exe

